package com.jxtti.service;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jxtti.dao.ArticleListDao;
import com.jxtti.entity.ArticleList;

@Service("ArticleListService")
@Transactional(rollbackFor = { RuntimeException.class, Exception.class })
public class ArticleListService {
	private final static Logger log = Logger
			.getLogger(ArticleListService.class);

	@Autowired
	private ArticleListDao<ArticleList> articleListDao;

	/**
	 * 获取信息数据列表-----分页
	 * 
	 * @param data
	 * @return
	 */
	public PageInfo<ArticleList> list(Map<String, Object> data) {
		// 第几页
		int pageNum = Integer.parseInt((data.get("page") == null || data.get(
				"page").equals("0")) ? "1" : data.get("page").toString());
		// 每页显示条数 
		int pageSize = Integer.parseInt((data.get("rows") == null || data.get(
				"rows").equals("0")) ? "10" : data.get("rows").toString());

		PageHelper.startPage(pageNum, pageSize);
		PageInfo<ArticleList> pages = new PageInfo<ArticleList>(
				articleListDao.queryByList(data));
		return pages;
	}

	// 前台分页
	public PageInfo<ArticleList> listPage(Map<String, Object> data) {
		// 第几页
		int pageNum = Integer.parseInt((data.get("currPageNum") == null || data.get("currPageNum").equals("0")) ? "1" : data.get("currPageNum").toString());
		// 每页显示条数 
		int pageSize = Integer.parseInt((data.get("pageRowSize") == null || data.get("pageRowSize").equals("0")) ? "10" : data.get("pageRowSize").toString());

		PageHelper.startPage(pageNum, pageSize);
		PageInfo<ArticleList> pages = new PageInfo<ArticleList>(articleListDao.queryListForIndex(data));
		return pages;
	}

	public List<ArticleList> queryAll(Map<String, Object> data) {
		return articleListDao.queryByList(data);
	}

	public List<ArticleList> chartAudit(Map<String, Object> data) {
		return articleListDao.chartAudit(data);
	}

	public List<ArticleList> chartAuditLine(Map<String, Object> data) {
		return articleListDao.chartAuditLine(data);
	}

	public List<ArticleList> chartArticleCy(Map<String, Object> data) {
		return articleListDao.chartArticleCy(data);
	}

	public List<ArticleList> queryListForIndex(Map<String, Object> data) {
		return articleListDao.queryListForIndex(data);
	}

	public List<ArticleList> queryPreNext(Map<String, Object> data) {
		return articleListDao.queryPreNext(data);
	}

	public int add(ArticleList entity) {
		int insertCount = articleListDao.add(entity);
		return insertCount;
	}

	public int update(ArticleList entity) {
		int updateCount = articleListDao.update(entity);
		return updateCount;
	}

	public int delete(ArticleList entity) {
		int deleteCount = articleListDao.delete(entity);
		return deleteCount;
	}

	public ArticleList queryById(ArticleList entity) {
		entity = articleListDao.queryById(entity);
		return entity;
	}

	
	public List<ArticleList>  cteTreeArticleListByCategoryID(Map<String, Object> data)
	{
		return articleListDao.cteTreeArticleListByCategoryID( data);
	}
	
	
	// 前台分页
	/**
	 * 根据跟目录 ID　　查所有文章并前端分面处理.
	 * @param data
	 * @return
	 */
	public PageInfo<ArticleList> cteTreeArticleListByCategoryIDByPage(Map<String, Object> data) {
		// 第几页
		int pageNum = Integer.parseInt((data.get("currPageNum") == null || data
				.get("currPageNum").equals("0")) ? "1" : data
				.get("currPageNum").toString());
		// 每页显示条数 
		int pageSize = Integer
				.parseInt((data.get("pageRowSize") == null || data.get(
						"pageRowSize").equals("0")) ? "10" : data.get(
						"pageRowSize").toString());

		PageHelper.startPage(pageNum, pageSize);
		PageInfo<ArticleList> pages = new PageInfo<ArticleList>(
				articleListDao.cteTreeArticleListByCategoryID(data));
		return pages;
	}
	
}
